package com.hts.spring05.biz;

import com.hts.spring05.dao.UserDao;
import com.hts.spring05.dao.UserDaoMysqlImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

//@Service
public class UserServiceImpl implements UserService {
    // 自动注入

    /*
       自动装配, 前提是 容器中有且只有一个实例对象,如果有多个的情况就会报错
       2. 如果有多个符合条件的对象, 就可以使用Qualifier 指定对象名称
     */
//    @Autowired
//    @Qualifier("userDaoSqlServerImpl")
    private UserDao userDao;



    @Autowired
    private List<UserDao> daos;

    @Autowired
    private Map<String,UserDao> maps;


    public UserServiceImpl(@Qualifier("userDaoMysqlImpl") UserDao userDap) {
        this.userDao = userDap;
    }

    public void add() {
        userDao.add();
        System.out.println(this.daos);

        UserDao userDaoMysqlImpl = this.maps.get("userDaoMysqlImpl");
        UserDao userDaoSqlServerImpl = this.maps.get("userDaoSqlServerImpl");
        System.out.println(userDaoMysqlImpl);
        System.out.println(userDaoSqlServerImpl);

    }

    public UserDao getUserDao() {
        return userDao;
    }

    //    @Autowired
//    @Qualifier("userDaoSqlServerImpl")
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
}
